package com.vercon.common.view;

import android.annotation.SuppressLint;
import android.content.Context;
import android.graphics.Rect;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.widget.TextView;

@SuppressLint("AppCompatCustomView")
public class MarqueeForeverTextView extends TextView {

    public MarqueeForeverTextView(Context context) {
        this(context, null);
    }
    public MarqueeForeverTextView(Context context, AttributeSet attrs) {
        super(context, attrs);
        initTypeFace(context);
        setFocusable(true);
        setFocusableInTouchMode(true);
        setSingleLine();
        setEllipsize(TextUtils.TruncateAt.MARQUEE);
        setMarqueeRepeatLimit(-1);
    }

    public MarqueeForeverTextView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        initTypeFace(context);
        setFocusable(true);
        setFocusableInTouchMode(true);
        setSingleLine();
        setEllipsize(TextUtils.TruncateAt.MARQUEE);
        setMarqueeRepeatLimit(-1);
    }

    private void initTypeFace(Context context) {
        if (isInEditMode()) {
            if (getText().toString().trim().equals(""))
                setText("XXX");
        }
        setTypeface(FontProvider.getInstance(getContext()).getTypeface(FontProvider.chinese_type));
//        setTypeface(TypefaceUtil.createTypeface(context, FontProvider.chinese_type));
    }

    @Override
    protected void onFocusChanged(boolean focused, int direction, Rect previouslyFocusedRect) {
        if (focused) {
            super.onFocusChanged(focused, direction, previouslyFocusedRect);
        }
    }


    @Override
    public void onWindowFocusChanged(boolean focused) {
        if (focused) {
            super.onWindowFocusChanged(focused);
        }
    }

    @Override
    public boolean isFocused() {
        return true;

    }

}